package com.niiwoo.civet.trade.service.local.third;

import com.alibaba.fastjson.JSON;
import com.niiwoo.asset.constant.MqConstants;
import com.niiwoo.civet.trade.dao.entity.Project;
import com.niiwoo.civet.trade.dao.mapper.ProjectMapperExt;
import com.niiwoo.civet.trade.enums.ProjectFromSourceEnum;
import com.niiwoo.tripod.rabbitmq.component.ConsistencyRabbitTemplate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by yuanguang on 2018/1/31.
 */
@Service
@Slf4j
public class AssetSideLocalService {
    @Autowired
    private ProjectMapperExt projectMapperExt;
    @Autowired
    private ConsistencyRabbitTemplate consistencyRabbitTemplate;
    public void sendMqToAssetSide(Long projectId){

        Project project = projectMapperExt.selectByPrimaryKey(projectId);
        if (project != null && project.getFromSource() == ProjectFromSourceEnum.R360.getType().byteValue()){
            //todo 调用融360接口更新还款计划
            Map<String,Long> map=new HashMap<>();
            map.put("projectId",projectId);
            Message msg = new Message(JSON.toJSONString(map).getBytes(Charset.forName("UTF-8")), null);
            consistencyRabbitTemplate.send(MqConstants.Exchange.ASSET_EXCHANGE,MqConstants.getRoutingKey(MqConstants.Exchange.ASSET_EXCHANGE,MqConstants.Queue.REPAYMENT_PLAN_PUSH),msg);
        }
    }
}
